using Engine.Graphics.VertexStructures;
using SharpDX;
using SharpDX.Direct3D11;

namespace Engine.FileFormats3D.WR2TrafficFiles
{
    public class RenderStreet
    {
        #region Private Fields

        private CustomVertex.PositionColored[] positions;
        private Buffer vb;

        #endregion Private Fields

        #region Public Constructors

        public RenderStreet(Device device, Vector3[] Positions, System.Drawing.Color color)
        {
            positions = new CustomVertex.PositionColored[Positions.Length];
            for (int i = 0; i < positions.Length; i++)
            {
                positions[1].Color = new Color4(System.Drawing.Color.Violet.ToArgb());
                //Positions[i].Scale(0.1f);
                positions[i].Position = Positions[i];
                positions[i].Color = new Color4(color.ToArgb());
            }

            BufferDescription vertexBufferdescription = new BufferDescription()
            {
                BindFlags = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.Write,
                OptionFlags = ResourceOptionFlags.None,
                SizeInBytes = positions.Length * CustomVertex.PositionColored.SizeInBytes(),
                StructureByteStride = CustomVertex.PositionColored.SizeInBytes(),
                Usage = ResourceUsage.Default
            };

            DeviceContext de = new DeviceContext(device);

            //vb = new Buffer(device, positions.Length * CustomVertex.PositionColored.SizeInBytes(), Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Managed);
            vb = new Buffer(device, vertexBufferdescription);

            using (DataStream vertexStream = DataStream.Create<CustomVertex.PositionColored>(positions, false, false))
            {
                vertexStream.WriteRange(positions);
            }
        }

        #endregion Public Constructors

        #region Public Methods

        public void Dispose()
        {
            if (vb != null)
                vb.Dispose();
        }

        public void Draw(Device device)
        {
            //EffectTechnique effect = new EffectTechnique(System.IntPtr.Zero);
            //EffectPass effectPass = effect.GetPassByIndex(0);
            //effectPass.VertexShaderDescription.ToString();
            //    Effect
            //device.ImmediateContext.  =
            //device.SetStreamSource(0, vb, 0, CustomVertex.PositionColored.SizeInBytes());
            //device.VertexFormat = CustomVertex.PositionColored.Format;
            //device.DrawPrimitives(PrimitiveType.LineStrip, 0, positions.Length - 1);
        }

        #endregion Public Methods
    }
}